#include <stdlib.h>
#include <clutter/clutter.h>

#define WINDOWS_WIDTH 400
#define WINDOWS_HEIGHT 400
#define FLOWER_WIDTH 180
#define FLOWER_HEIGHT 380
#define UNUSED(x) (void)x

ClutterActor * rect, * label;

static gboolean on_stage_button_press(ClutterStage *stage, ClutterEvent *event, gpointer data)
{
    UNUSED(stage);
    UNUSED(event);
    UNUSED(data);
    static int click_num = 0;
    static double angle =0.0;
    static ClutterRotateAxis axis = CLUTTER_X_AXIS;
    angle += 10;

    //Rotaion Testing。指定转轴的方向，以及转轴的位置，因此如果X轴，通过这是Y、Z来给出转轴位置 
    switch(axis){
    case CLUTTER_X_AXIS:
        clutter_actor_set_rotation_angle (rect, CLUTTER_X_AXIS, angle);
        
        if(angle > 359){
                angle = 0.0;
                axis = CLUTTER_Y_AXIS;
        }
        return TRUE;
    case CLUTTER_Y_AXIS:
        clutter_actor_set_rotation_angle (rect, CLUTTER_Y_AXIS, angle);
        if(angle > 359){
                angle = 0.0;
                axis = CLUTTER_Z_AXIS;
        }
        return TRUE;
    case CLUTTER_Z_AXIS:
        clutter_actor_set_rotation_angle (rect, CLUTTER_Z_AXIS, angle);
        if(angle > 359){
                angle = 0.0;
                axis = -1;
        }
        return TRUE;
    default:
            break;
    }
    //End of Rotaion Testing

    click_num ++;
    switch(click_num ){
    case 1:
        //缩放实验，参数二、三分别表示X轴和Y轴的缩放 
        clutter_actor_set_scale (label,3.0,1.0);
        clutter_actor_set_scale(rect,1.2,1.0);
        break;
    case 2:
        clutter_actor_set_scale(label,3.0,2.0);
        clutter_actor_set_scale(rect,1.0,1.0);//恢复原来尺寸 
        break;
    case 3:
        //部分显示实验，参数分别表示从哪开始显示，显示的大小，可视部分是方形 
        clutter_actor_set_scale(label,3.0,3.0);
        clutter_actor_set_clip (rect,20.0,20.0,50.0,50.0);
        break;
    case 4:
        clutter_actor_set_scale(label,1.0,1.0);
        printf("Clip REMOVE Test:");
        clutter_actor_remove_clip (rect);//去除删减 
        break;
    default:
        //移位测试，当然我们也可以用set_position的方式，但是那需要计算在stage的位置，这里只需给出每次的位移。 
        clutter_actor_move_by (rect,-10,5);
        clutter_actor_move_by(label,0,-10);
        break;
    }

    return TRUE;
}

 

int main(int argc , char * argv[])
{
    /* 对于color的第四个参数alpha因子的测试表明，这是亮度或者灰度，实际RBG的值是前面的数值*alpha/256 */
    ClutterColor stage_color ={0x00,0x00,0x00,0xff};
    ClutterColor actor_color ={0xff,0xff,0xff,0xB0};

    if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
    {
        return EXIT_FAILURE;
    }

    ClutterActor *stage = clutter_stage_new();
    clutter_stage_set_title (CLUTTER_STAGE (stage), "ClutterAnimate");
    clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), TRUE);
    clutter_actor_set_size(stage, WINDOWS_WIDTH, WINDOWS_HEIGHT);
    g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);

    /* 在stage中添加一个方框（已注释）或者一个图片，用于后诉的兼容性的试验 */ 
    rect = clutter_texture_new_from_file("../assert/back.png" ,NULL);
    clutter_actor_add_child( stage, rect);
    clutter_actor_set_position(rect,150,100);

    /* 在stage中加入一个label */ 
    label = clutter_text_new_full ("微软雅黑 14", "你好，朋友", &actor_color);
    clutter_actor_set_position(label,150,240);
    clutter_actor_add_child(stage, label);
    g_signal_connect(stage,"button-press-event",G_CALLBACK(on_stage_button_press),NULL);

    clutter_actor_show (stage);
    clutter_main();
    return EXIT_SUCCESS;
}